﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


using KingRoad.EPM.SafetyManagementEntity.Model;
using Unis.Framework.Core.Utility;
using KingRoad.EPM.SafetyManagementDAL.ProjectSegmentService;


namespace KingRoad.EPM.SafetyManagementBLL.UIRules
{
    /// <summary> 
    /// 客户端业务处理类。 
    /// 文件生成时间 2017/1/12 13:59:00
    /// </summary> 
    public class ProjectSegmentUIRule
    {
        private readonly IProjectSegmentService _projectSegmentService;
        
        
        public ProjectSegmentUIRule(){}
        
        /// <summary> 
        /// construct function... 
        /// </summary> 
        public ProjectSegmentUIRule(IProjectSegmentService  projectSegmentService)
        {
           _projectSegmentService=projectSegmentService;
        }

        /// <summary>
        /// 根据条件获取单位信息(分页)
        /// </summary>
        /// <param name="numCurrentPage">当前页</param>
        /// <param name="numPerPage">每页数据大小</param>
        /// <param name="orderByField">排序字段名称</param>
        /// <param name="totalRecord">总数据量</param>
        /// <param name="sqlCondition">sql查询条件</param>
        /// <returns></returns>
        public List<ProjectSegmentInfo> GetProjectSegmentListForPage(int numCurrentPage, int numPerPage,
                                                                        string orderByField, out int totalRecord, string sqlCondition)
        {
            var list = _projectSegmentService.GetEntityListByContionRe(numCurrentPage, numPerPage, orderByField, out totalRecord, sqlCondition);
            return list;
        }

        public List<K> GetProjectSegmentListForPage<K>(int numCurrentPage, int numPerPage,
                                                                      string orderByField, List<K> listSource) where K : new()
        {
            var list = _projectSegmentService.GetEntityListByContionRe(numCurrentPage, numPerPage, orderByField, listSource);
            return list;
        }
        /// <summary>
        /// 根据条件获取信息
        /// </summary>
        /// <returns></returns>
        public ProjectSegmentInfo GetProjectSegmentBySql(string sql)
        {
            var spminfo = _projectSegmentService.GetEntityList(sql).FirstOrDefault();
            return spminfo;
        }
        /// <summary>
        /// 根据施工单位类型获取信息
        /// </summary>
        /// <param name="type">单位类型</param>
        /// <returns></returns>
        public List<ProjectSegmentInfo> GetSegmentListByType(int type)
        {
            string sql = " 1=1 ";
            if (type != null)
            {
                sql = "SEGMENT_TYPE="+type;
            }
            var spminfo = _projectSegmentService.GetEntityList(sql);
            return spminfo;
        }
    }
}
